package com.woniuxy.controller;

import cn.hutool.http.server.HttpServerRequest;
import com.woniuxy.pojo.User;
import com.woniuxy.service.CustomerService;
import com.woniuxy.service.ServiceService;
import com.woniuxy.service.UserService;
import com.woniuxy.util.TreeNode;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.session.Session;
import org.apache.shiro.subject.Subject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.HttpRequestHandler;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Controller
public class IndexController {
    private Logger logger= LoggerFactory.getLogger(this.getClass());
    @Autowired
    private UserService userService;
    @Autowired
    ServiceService serviceService;
    @Autowired
    CustomerService customerService;

    @RequestMapping(value = "/index.do")
    public String index() {
        return "index";
    }

    @RequestMapping(value = "/initIndexMenu.do")
    @ResponseBody
    public List<TreeNode> initIndexMenu() {
        Subject subject = SecurityUtils.getSubject();
        Session session = subject.getSession();
        User user = (User) session.getAttribute("USER_SESSION");
        List<TreeNode> treeNodes = userService.selectMenusByUid(user.getId());
        return treeNodes;
    }

    @RequestMapping(value = "/toUserManager.do")
    public String toUserManager() {
        return "user/userList";
    }

    @RequestMapping(value = "/toUserAddPage.do")
    public String toUserAddPage() {
        return "user/userAdd";
    }

    @RequestMapping(value = "/toUserRolePage.do")
    public String toUserRolePage() {
        return "user/userRole";
    }

    @RequestMapping(value = "/toPerssionManager.do")
    public String toperManager() {
        return "user/perList";
    }

    @RequestMapping(value = "/toRoleManager.do")
    public String toRoleManager() {
        return "role/roleList";
    }

    @RequestMapping(value = "/toAssignRightPage.do")
    public String toAssignRightPage() {
        return "role/assignRight";
    }

    @RequestMapping(value = "/toUserEidtPage.do")
    public String toUserEditPage() {
        return "user/userEdit";
    }
    @RequestMapping(value = "/userinfo.do")
    public String toUserInfo() {
        return "user/userInfo";
    }

    //销售机会显示
    @RequestMapping(value = "/toSaleChance.do")
    public String toSaleChance() {
        return "sale/saleChanceList";
    }

    //销售机会增加
    @RequestMapping(value = "toSaleChanceAddPage.do")
    public String toSaleChanceAddPage() {
        return "sale/saleChanceAdd";
    }

    /**
     * 服务模块
     *
     * @return
     */
    //创建页面
    @RequestMapping("/toServiceAddPage.do")
    public String toServiceAddPage(HttpServletRequest request) {
        return "services/newWorkOrder";
    }

    //分配页面
    @RequestMapping("/toServiceEditPage.do")
    public String toServiceEditPage(HttpServletRequest request) {
        return "services/serviceEdit";
    }

    //处理页面
    @RequestMapping("/toServiceDealPage.do")
    public String toServiceDealPage(HttpServletRequest request) {
        return "services/serviceDeal";
    }

    //服务处理详情页
    @RequestMapping("/toServiceInner.do")
    public String toServiceDealInner() {
        return "/services/serviceInner";
    }

    //服务预览页面
    @RequestMapping("/toServiceLookPage.do")
    public String toServiceLookPage() {
        return "/services/serviceLookPage";
    }

    //服务反馈页面
    @RequestMapping("/toServiceResultPage.do")
    public String toServiceResultPage() {
        return "services/serviceResult";
    }

    //服务反馈详情页
    @RequestMapping("/toServiceResultInner.do")
    public String toServiceResultInner() {
        return "services/serviceResultInner";
    }

    //服务单归档
    @RequestMapping("toServiceFeedbackPage.do")
    public String toServiceFeedbackPage() {
        return  "services/serviceFeedback";
    }
    //服务归档详情页
    @RequestMapping("/toServiceFeedbackInner.do")
    public String toServiceFeedbackInner(){
        return "services/serviceFeedbackInner";
    }
    //进入服务单分配相应也
    @RequestMapping(value = "/toDistributeService.do")
    public String toDistributeService() {
        return "services/distributeService";
    }
    @RequestMapping("/toServiceData.do")
    public String toServiceData(){
        return "services/serviceData";
    }

    //销售机会编辑
    @RequestMapping("toSaleChanceEidtPage.do")
    public String toSaleChanceEidtPage() {
        return "sale/saleChanceEdit";
    }

    //销售机会指派
    @RequestMapping("toSaleChanceAssignPage.do")
    public String toSaleChanceAssignPage() {
        return "sale/saleChanceAssign";
    }

    //客户开发计划
    @RequestMapping("toDevPlan.do")
    public String toDevPlan() {
        return "sale/customerDevPlanList";
    }
    //制定开发计划
    @RequestMapping(value = "toDevelopmentPlanPage.do")
    public String toDevelopmentPlanPage(){
        return "sale/customerDevPlan";
    }
    //编辑开发计划
    @RequestMapping("toImportPlan.do")
    public String toImportPlan(){
        return "sale/importPaln";
    }
    @RequestMapping("toImportResult.do")
    public String toImportResult(){
        return "sale/importResult";
    }
    //客户贡献跳转页面
    @RequestMapping("toCustomerContribute.do")
    public String toCustomerContribute(){
        return "statement/customerContribution";
    }
    //按下执行开发计划之后跳转页面
    @RequestMapping("toExecutePlan.do")
    public String toExecutePlan(){
        return "sale/executePlan";
    }

    @RequestMapping(value = "/toCustLostManager.do")
    public String toCustLostManager() {
        return "customer/custLostList";
    }

    //暂缓流失客户页面
    @RequestMapping(value = "/todeferCustomer.do")
    public String todeferCustomer() {
        return "customer/deferCustomer";
    }

    //确认流失页面
    @RequestMapping("/toconfireLostCustomer.do")
    public String toconfireLostCustomer() {
        return "customer/confireLostCustomer";
    }

    @RequestMapping(value = "toBasicDictionary.do")
    public String toBasicDictionary() {
        return "basicData/basicDataList";
    }

    //编辑基础数据页面导航
    @RequestMapping(value = "toEditBasicData.do")
    public String toEditBasicData() {
        return "basicData/editBasicData";
    }

    //产品页面
    @RequestMapping(value = "toProduct.do")
    public String toProduct() {
        return "product/productList";
    }

    //库存页面
    @RequestMapping(value = "toRepertory.do")
    public String toRepertory() {
        return "repertory/repertoryList";
    }

    //客户流失分析页面
    @RequestMapping("toCustLostAnalyze.do")
    public String toCustLostAnalyze() {
        return "analyze/custLostAnalyze";
    }
    //客户主页面
    @RequestMapping(value = "/toCustomerManager.do")
    public String toCustomerManager(){
        return "customer/customerList";
    }
    @RequestMapping(value = "/toCustomerAddPage.do")
    public String toCustomerAddPage(){
        return "customer/customerAdd";
    }
    @RequestMapping(value = "/toCustomerEidtPage.do")
    public String toCustomerEditPage(){
        return "customer/customerEdit";
    }
    //联系人页面
    @RequestMapping(value = "/toLinkmanPage.do")
    public String toLinkmanPage(){
        return "linkman/linkmanList";
    }
    @RequestMapping(value = "/toLinkmanAddPage.do")
    public String toLinkmanAddPage(){
        return "linkman/linkmanAdd";
    }
    @RequestMapping(value = "/toLinkmanEidtPage.do")
    public String toLinkmanEditPage(){
        return "linkman/linkmanEdit";
    }
    @RequestMapping(value = "/toLinkmanViewPage.do")
    public String toLinkmanViewPage(){
        return "linkman/linkmanView";
    }

    //业务交流页面
    @RequestMapping(value = "/toCommunicationPage.do")
    public String toCommunicationPage(){
        return "communication/communicationList";
    }
    @RequestMapping(value = "/toCommunicationAddPage.do")
    public String toCommunicationAddPage(){
        return "communication/communicationAdd";
    }
    @RequestMapping(value = "/toCommunicationEidtPage.do")
    public String toCommunicationEidtPage(){
        return "communication/communicationEidt";
    }
    @RequestMapping(value = "/toCommunicationViewPage.do")
    public String toCommunicationViewPage(){
        return "communication/CommunicationView";
    }
    //订单页面
    @RequestMapping(value = "/toOrderPage.do")
    public String toOrderPage(){
        return "order/orderList";
    }
    @RequestMapping(value = "/toOrderProductPage.do")
    public String toOrderProductPage(){
        return "order/orderProductList";
    }
    //顾客树状图
    @RequestMapping(value = "/toCustomertable.do")
    public String toCustomertabletPage(){
        return "table/customertable";
    }

    //测试页面
    @RequestMapping("test.do")
    public String test(){
        return "dynamicCode1";
    }
    //到修改密码页面
    @RequestMapping("toChangePwd.do")
    public String toChangePwd(){
        return "changePwd";
    }
    //到首页
    @RequestMapping("toMain.do")
    public String toMain(){
        return "user/main";
    }

    //找回密码测试
    @RequestMapping("find")
    public String findPassword(){
        return "findPassword";
    }
    //打开的开发计划中的效果详情页
    @RequestMapping("toDetails.do")
    public String toDetails(){
        return "sale/resultDetails";
    }

    //到日志页面
    @RequestMapping(value = "toSysLogManager.do")
    public String toSysLogManager(){
        return "sysLog/sysLogList";
    }

    @RequestMapping(value = "toLoginSysLogManager.do")
    public String toLoginSysLogManager(){
        return "sysLog/loginsysLogList";
    }


    //添加基础数据
    @RequestMapping("toAddBasicData.do")
    public String addBasicData(){
        return "basicData/basicDataAdd";
    }
    @RequestMapping("toCustWillLostManager.do")
    public String toCustWillLostManager(){
        return "customer/custWillLostList";
    }

    //未分配页面
    @RequestMapping("toNoAssignSaleChance.do")
    public String toNoAssignSaleChance(){
        return "sale/noAssignSaleChanceList";
    }
    //待开发页面
    @RequestMapping("toNoSuccessDevPlan.do")
    public String toNoSuccessDevPlan(){
        return "sale/noSuccessDevPlanList";
    }

}
